package com.lrkj.web.phone;


import com.lrkj.common.annotation.Log;
import com.lrkj.common.constant.UserConstants;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.waitress.domain.CustomInfo;
import com.lrkj.waitress.domain.JoinFile;
import com.lrkj.waitress.domain.Repairs;
import com.lrkj.waitress.domain.RoomCustom;
import com.lrkj.waitress.service.ICustomInfoService;
import com.lrkj.waitress.service.IJoinFileService;
import com.lrkj.waitress.service.IRepairsService;
import com.lrkj.waitress.service.IRoomCustomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "手机端客户服务")
public class WaitressController extends BaseController {

    @Autowired
    private ICustomInfoService customInfoService;

    @Autowired
    private IRoomCustomService roomCustomService;

    @Autowired
    private IRepairsService repairsService;

    @Autowired
    private IJoinFileService joinFileService;



    /**
     * 根据openId查询客户信息
     */
    @ApiOperation(value = "根据openId查询客户信息", notes = "根据openId查询客户信息")
    @GetMapping("/phone/customInfo/list")
    public TableDataInfo CustomInfolist(CustomInfo customInfo) {
        startPage();
        this.changeParameter(customInfo.getParams());
        List<CustomInfo> list = customInfoService.selectCustomInfoList(customInfo);
        return getDataTable(list);
    }


    /**
     * 业主成员列表
     */
    @ApiOperation(value = "业主成员列表", notes = "业主成员列表")
    @GetMapping(value = "/phone/customInfo/roomCustomList")
    public AjaxResult roomCustomList(RoomCustom roomCustom) {
        this.changeParameter(roomCustom.getParams());
        return AjaxResult.success(roomCustomService.selectRoomCustomList(roomCustom));
    }

    /**
     * 新增入伙材料
     */
    @ApiOperation(value = "新增入伙材料", notes = "新增入伙材料")
    @Log(title = "入伙材料", businessType = BusinessType.INSERT)
    @PostMapping("/phone/joinFile")
    public AjaxResult add(@RequestBody JoinFile joinFile)
    {
        return toAjax(joinFileService.insertJoinFile(joinFile));
    }


    /**
     * 新增业主成员
     */
    @ApiOperation(value = "新增业主成员", notes = "新增业主成员")
    @Log(title = "业主成员", businessType = BusinessType.INSERT)
    @PostMapping("/phone/customInfo/addFamily")
    public AjaxResult addFamily(@RequestBody RoomCustom roomCustom) {
        return toAjax(roomCustomService.doSavaOrUpdate(roomCustom));
    }


    /**
     * 修改客户管理
     */
    @ApiOperation(value = "修改客户管理", notes = "修改客户管理")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/phone/customInfo")
    public AjaxResult edit(@RequestBody CustomInfo customInfo) {
        if (UserConstants.NOT_UNIQUE.equals(customInfoService.checkCodeUnique(customInfo))) {
            return AjaxResult.error("客户名称'" + customInfo.getCustomName() + "'已存在");
        }
        return toAjax(customInfoService.updateCustomInfo(customInfo));
    }


    /**
     * 获取客户管理详细信息
     */
    @ApiOperation(value = "获取客户管理详细信息", notes = "获取客户管理详细信息")
    @GetMapping(value = "/phone/customInfo/{customId}")
    public AjaxResult getInfo(@PathVariable("customId") String customId) {
        return AjaxResult.success(customInfoService.selectCustomInfoById(customId));
    }


    /**
     * 查询投诉建议列表
     */
    @ApiOperation(value = "查询投诉建议列表", notes = "查询投诉建议列表")
    @GetMapping("/phone/repairs/list")
    public TableDataInfo Repairslist(Repairs repairs)
    {
        startPage();
        List<Repairs> list = repairsService.selectRepairsList(repairs);
        return getDataTable(list);
    }


}
